home *** CD-ROM | disk | FTP | other *** search
/ Deutsche Edition 1 / Deutsche Edition 1.iso / amok / 031-040 / amok35 / spellchecker / lexi.def < prev    next >
Text File  |  1993-11-04  |  5KB  |  160 lines

  1. (*********************************************************************
  2.   :Program.    Lexi.def
  3.   :Contents.   Basic funktions for Spellchecker
  4.   :Author.     Stefan Salewski
  5.   :Copyright.  PD
  6.   :Language.   Modula-2
  7.   :Translator. M2Amiga AMSoft V3.3d
  8.   :History.    V1.0 1.Mar.1990
  9.   :Address.    Stolper Weg 3, D-2160 Stade
  10.   :Imports.    TurboFilesV1.1, Assembler2V1.1 (my own)
  11.   :Imports.    MemSystem (Nicolas Benezan)
  12. *********************************************************************)
  13.  
  14. DEFINITION MODULE Lexi;
  15.   FROM Exec IMPORT UByte;
  16.   FROM TurboFiles IMPORT FilePtr;
  17.  
  18.   CONST
  19.     MinWordLength=2;
  20.     MaxWordLength=14;
  21.     MinFracSizeI=6;
  22.     MinFracSizeS=4;
  23.     MinWords=10000;
  24.     MoreWords=1000;
  25.     TmpLexName='T:Lexi.tmp';
  26.  
  27.   (*
  28.      InsertWord() inserts only words with
  29.      MinWordLength <= Length(word) <= maxWordLength.
  30.      SearchString divides large words in components.
  31.      If a component is found in Lexikon and
  32.      Length(thisComponent) >= MinFracSizeS then this component is
  33.      deletet from the initial string and we go on with this rest.
  34.      If Length(thisRest)>=MinFracSizeI then this rest is inserted into
  35.      the Lexikon
  36.  
  37.      MinWords is the free space when we start the programm. If we
  38.      try to insert more words than MinWords, the Lexikon is saved
  39.      as TmpLexName, Space for MinWords+MoreWords is allocated and
  40.      the lexikon is loaded again.
  41.   *)
  42.  
  43.   TYPE
  44.     Infos=(cap,hyphen,bHyphen);
  45.     InfoSet=SET OF Infos;
  46.     Word=ARRAY[0..MaxWordLength] OF CHAR;
  47.  
  48.   PROCEDURE InitLex;
  49.   (*
  50.     Set the number of words in Lex to zero
  51.   *)
  52.  
  53.   PROCEDURE ExpandLex(VAR textName:ARRAY OF CHAR):BOOLEAN;
  54.   (*
  55.     Reads words from file textName and inserts them in Lexikon.
  56.     If the word is allready in Lexikon, the counter of this word is
  57.     increased. Returns FALSE if it is not possible to open the file.
  58.   *)
  59.  
  60.   PROCEDURE CleanLex(VAR cleanName:ARRAY OF CHAR):UByte;
  61.   (*
  62.     Every word has a counter (one Byte) which shows how often this
  63.     word is allready found in textfiles. CleanLex kills all words
  64.     with the lowest counter. The first call of CleanLex will kill
  65.     all words with counter=1, the next call words with counter=2 ...
  66.     RETURNS the counter of the deleted words.
  67.   *)
  68.  
  69.   PROCEDURE SearchString(VAR w:ARRAY OF CHAR;VAR pos:CARDINAL;inc:UByte):BOOLEAN;
  70.   (*
  71.     Search for the string w in the lexikon. If w consists of more words,
  72.     then w is splitted in components. Returns TRUE if the word is found in
  73.     the Lexikon. In this case w and pos are undefined.
  74.     RETURNS FALSE if the word is not found. If pos#0, we can Insert()
  75.     w at position pos in Lexikon. If pos=0, we can NOT insert it, maybe
  76.     the word is too long. This procedure changes w ! For example, if
  77.     w=computertable, and table is allready in the lexikon, then we get
  78.     back w=computer and pos is the position to Insert() computer.
  79.     If a word is found in the Lexikon, then its counter is increased by inc.
  80.   *)
  81.  
  82.   PROCEDURE InsertWord(VAR w:Word;pos:CARDINAL;count:UByte);
  83.   (*
  84.     Inserts w at position pos in Lexikon and sets its counter to
  85.     startvalue count. pos should be the position determed by SearchString,
  86.     because the words in Lexikon are sorted alphabetical.
  87.   *)
  88.  
  89.   PROCEDURE DeleteWord(VAR w:Word):BOOLEAN;
  90.   (*
  91.     Search for w and delete it. RETURNS FALSE if word is not found.
  92.   *)
  93.  
  94.   PROCEDURE SaveLex(VAR lexName:ARRAY OF CHAR):BOOLEAN;
  95.   (*
  96.     Save Lexikon to File with name lexName
  97.   *)
  98.  
  99.   PROCEDURE LoadLex(VAR lexName:ARRAY OF CHAR):BOOLEAN;
  100.   (*
  101.     Load Lexikon from disk
  102.   *)
  103.  
  104.   PROCEDURE ExportLex(VAR exportName:ARRAY OF CHAR):BOOLEAN;
  105.   (*
  106.     Save Lexikon to a textfile. We can use an editor to change this file
  107.     and then import it again by using ExpandLex
  108.   *)
  109.  
  110.   PROCEDURE WordsInLex():CARDINAL;
  111.   (*
  112.     Returns the number of words currently in Lexikon
  113.   *)
  114.  
  115.   PROCEDURE MinCount():UByte;
  116.   (*
  117.     All words in Lexikon have a counter. We set this counter to a
  118.     startvalue if we Insert() this word and increase it every
  119.     time when SearchString found this word.
  120.     MinCount() Returns the minimun count of all words in Lexikon
  121.   *)
  122.  
  123.   PROCEDURE MaxCount():UByte;
  124.   (*
  125.     Returns the maximum count
  126.   *)
  127.  
  128.   PROCEDURE ReadWord(source,echo:FilePtr;
  129.                      VAR str:ARRAY OF CHAR;VAR info:InfoSet;
  130.                      minLength,maxLength:CARDINAL);
  131.   (*
  132.     Reads a word from open file source. str contains this word if
  133.     minLength<=Length(word)<=maxLenght , otherwise str[0]=0C
  134.     If in front of this word there was '.', '?', '!', or ':' then
  135.     (cap IN info)=TRUE.
  136.     IF in front of this word there was a '-' then (hyphen IN info)=TRUE
  137.     IF in front of this word there was a CHAR(4) then
  138.     (bHyphen IN info)=TRUE
  139.     IF echo#NIL, then ReadWord writes every character that it reads
  140.     from source to echo.
  141.   *)
  142.  
  143.   PROCEDURE Letter(c:CHAR):BOOLEAN;
  144.   (*
  145.     RETURNS TRUE if c is a Letter like 'A', 'a', 'ü' ...
  146.   *)
  147.  
  148.   PROCEDURE Cap(c:CHAR):CHAR;
  149.   (*
  150.     Like CAP() but works although with 'ü', 'ö', ...
  151.   *)
  152.  
  153.   PROCEDURE IsCap(c:CHAR):BOOLEAN;
  154.   (*
  155.     RETURNS (Cap(c)=c)
  156.   *)
  157.  
  158. END Lexi.
  159.  
  160.